import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.math.*;
import java.util.*;
import java.util.Scanner;
import static java.lang.Math.pow;
import static java.lang.System.out;

public class Main {
    static int[][] ret;
    static int n;
    public static void main1(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt(), x = in.nextInt();//x:预算
        int[] bud = new int[n+1];
        int[] hp = new int[n+1];
        for(int i = 1;i <= n;i++) {
            int a = in.nextInt();
            int b = in.nextInt();
            bud[i] = a-b-b;  //优惠金额-现价
            hp[i] = in.nextInt();
        }
        //选前i件，体积不超j，所能得到的最大价值

        int sum = 0;
        int[] tmp = new int[n+1]; //存放待定商品
        int pos = 1;
        for(int i = 1;i <= n;i++) {
            if(bud[i] >= 0) {
                sum += hp[i];
                x += bud[i];
            } else {
                tmp[pos++] = Math.abs(bud[i]);
            }

        }
        int[][] dp = new int[n+1][x+1];  //在前i选，保证预算 >= j，能得到的最大happy值
        for(int i = 1;i < pos;i++) {
            for(int j = 1;j <= x;j++) {
                dp[i][j] = dp[i-1][j];
                if(j >= tmp[i]) dp[i][j] = Math.max(dp[i-1][j],dp[i-1][j-tmp[i]] + hp[i]);
            }
        }
        System.out.println(dp[pos-1][x]);
    }

    public static void main2(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt(), x = in.nextInt();//x:预算
        int[] bud = new int[n+1];
        int[] hp = new int[n+1];
        int sum = 0;  //总的快乐值
        int pos = 1;

        for(int i = 1;i <= n;i++) {
            int a = in.nextInt();
            int b = in.nextInt();
            int well = a-b-b;  //优惠金额-现价
            int happy = in.nextInt();
            if(well >= 0) {
                x += well;  //抬高预算
                sum += happy;
            } else {
                bud[pos] = Math.abs(well);
                hp[pos++] = happy;
            }
        }

        int[][] dp = new int[pos+1][x+1];  //在前i选，保证预算 >= j，能得到的最大happy值
        for(int i = 1;i < pos;i++) {
            for(int j = 1;j <= x;j++) {
                dp[i][j] = dp[i-1][j];
                if(j >= bud[i]) dp[i][j] = Math.max(dp[i-1][j],dp[i-1][j-bud[i]] + hp[i]);
            }
        }
        System.out.println(dp[pos-1][x] + sum);
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int ans = 1,n = 1;
        while(ans < 2023) {
            if(isHasde(n,2) && isHasde(n,8) && isHasde(n,10) && isHasde(n,16)) {
                ans++;
            }
            n++;
        }
        System.out.println(n);
        in.close();
    }

    public static boolean isHasde(int n,int x) {
        int[] a = new int[60];
        int pos = 0,tmp = n;
        while(tmp != 0) {
            a[pos++] = tmp % x;
            tmp /= x;
        }
        //此时pos为n的位数
        int sum = 0;
        for(int k : a) sum += k;
        if(n % sum != 0) return false;
        return true;
    }


}
